<template>
    <div id="parts task">
        <div class="operation">
            <el-button v-if="menuId==='4594'" @click="insertList" class="slot-btn-top" type="primary" size="small">
                发放任务
            </el-button>
            <el-button v-if="menuId==='4594'" @click="insertThisDayList" class="slot-btn-top" type="primary"
                       size="small">每日任务
            </el-button>
            <el-button v-if="menuId==='4594'" @click="openInstructions" class="slot-btn-top" type="success" size="small"
                       style="position: absolute;top: 5px;right: 10px;">使用说明
            </el-button>
        </div>
        <el-table :data="dataList.slice((currentPage-1)*pagesize,currentPage*pagesize)" :highlight-current-row="true" stripe border class="table-index" :height="tableHeight" style="width: 100%;" :header-cell-style="getRowClass">
            <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
            <el-table-column prop="taskName" label="任务名称" sortable min-width="140"></el-table-column>
            <el-table-column prop="creatorName" label="任务创建人" sortable min-width="120"></el-table-column>
            <el-table-column prop="performerName" label="任务执行人" sortable min-width="120"></el-table-column>
            <el-table-column prop="finishDate" label="需完成时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="isReceived" label="任务是否接收" :formatter="formatNeedTrain" sortable min-width="140"></el-table-column>
            <el-table-column prop="receivedDate" label="任务接收创建时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="startDate" label="任务实际开始时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="endDate" label="任务实际结束时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="taskResult" label="任务结果" :formatter="formatNeed2Train" sortable
                             min-width="130"></el-table-column>
            <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                <template slot-scope="scope">
                    <el-button @click="updateList(scope.row)" type="text" size="small">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                       :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagesize"
                       layout="total, sizes, prev, pager, next, jumper" :total="dataList.length"></el-pagination>

        <!-- 详情信息 -->
        <el-dialog :title="dialogTitle" width="90%" top="30px" :visible.sync="isDialog" :close-on-click-modal="false">
            <el-tabs v-model="activeName" @tab-click="handleClick" style="padding-bottom: 15px;">
                <el-tab-pane v-if="!isEveryDayTask" label="任务信息" name="1" class="dialog1" :style="dialogHeightPane">
                    <h3 class="dialog-plate-title"><span>基本信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right"
                             label-width="180px" style="margin-bottom: 0;">
                        <el-form-item label="*任务名称">
                            <el-input v-model="dialogList.taskName" :disabled="!dialogListDisabled.taskName"></el-input>
                        </el-form-item>
                        <el-form-item label="*完成时间">
                            <el-date-picker v-model="dialogList.finishDate" :disabled="!dialogListDisabled.finishDate"
                                            format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间"
                                            style="width: 200px;"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="*任务执行人所属部门">
                            <el-select v-model="dialogList.dept" :disabled="!dialogListDisabled.dept"
                                       @change="changeDept">
                                <el-option v-for="item in deptors" :key="item.id" :label="item.deptName"
                                           :value="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="*任务执行人">
                            <el-select v-model="dialogList.performer" :disabled="!dialogListDisabled.performer">
                                <el-option v-for="item in performName" :key="item.id" :label="item.name"
                                           :value="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="任务创建人">
                            <el-input v-model="dialogList.creatorName"
                                      :disabled="!dialogListDisabled.creatorName"></el-input>
                        </el-form-item>
                        <el-form-item label="任务创建时间">
                            <el-input v-model="dialogList.createDate"
                                      :disabled="!dialogListDisabled.createDate"></el-input>
                        </el-form-item>
                    </el-form>
                    <el-form v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="任务说明">
                            <el-button v-if="dialogType === '2'"  @click="insertMissionList" :disabled="!dialogListDisabled.taskContent" type="primary" size="small" style="margin-top: 20px;">新增任务说明</el-button>
                            <el-table v-if="dialogType === '2'" :data="missionData.slice((currentPage-1)*pagesize,currentPage*pagesize)" stripe border class="table-index" height="150" style="width: 99%;" :header-cell-style="getRowClass">
                                <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                                <el-table-column prop="time" label="填写时间" sortable min-width="170"></el-table-column>
                                <el-table-column prop="content" label="填写内容" sortable min-width="500"></el-table-column>
                                <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                                    <template slot-scope="scope">
                                        <el-button @click="updateMissionList(scope.row)" :disabled="!dialogListDisabled.taskContent" type="text" size="small">编辑</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                            <quill-editor  v-if="dialogType === '1'"  class="task" v-model="dialogList.taskContent"
                                          @focus="!dialogListDisabled.taskContent? onEditorFocus($event) : ''"
                                          style="padding-right: 10px;"></quill-editor>
                            <!--<el-input v-model="dialogList.taskContent"-->
                                      <!--:disabled="!dialogListDisabled.taskContent" type="textarea" size="middle"-->
                                      <!--style="width: 95%;"></el-input>-->
                        </el-form-item>
                    </el-form>

                    <h3 v-if="dialogType !== '1'" class="dialog-plate-title" ><span>接收信息</span></h3>
                    <el-form v-if="dialogType !== '1'" :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right"
                             label-width="180px" style="margin-bottom: 0;">
                        <el-form-item label="任务是否接收">
                            <el-select v-model="dialogList.isReceived" :disabled="!dialogListDisabled.isReceived">
                                <el-option label="【空】" value="-1"></el-option>
                                <el-option label="否" value="0"></el-option>
                                <el-option label="是" value="1"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="接收创建时间">
                            <el-date-picker v-model="dialogList.receivedDate"
                                            :disabled="!dialogListDisabled.receivedDate" format="yyyy-MM-dd HH:mm:ss"
                                            type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                        </el-form-item>
                    </el-form>
                    <el-form v-if="dialogType !== '1'" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="任务接收说明">
                            <el-button  @click="insertMissionReceiveList" :disabled="!dialogListDisabled.receivedDescription" type="primary" size="small" style="margin-top: 20px;">新增任务说明</el-button>
                            <el-table :data="missionReceiveData.slice((currentPage-1)*pagesize,currentPage*pagesize)" stripe border class="table-index" height="150" style="width: 99%;" :header-cell-style="getRowClass">
                                <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                                <el-table-column prop="time" label="填写时间" sortable min-width="170"></el-table-column>
                                <el-table-column prop="content" label="填写内容" sortable min-width="500"></el-table-column>
                                <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                                    <template slot-scope="scope">
                                        <el-button @click="updateMissionReceiveList(scope.row)" :disabled="!dialogListDisabled.receivedDescription" type="text" size="small">编辑</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>

                            <!--<quill-editor class="task" v-model="dialogList.receivedDescription"
                                          @focus="!dialogListDisabled.receivedDescription ? onEditorFocus($event) : ''"
                                          style="padding-right: 10px;"></quill-editor>-->
                            <!--<el-input v-model="dialogList.receivedDescription"-->
                                      <!--:disabled="!dialogListDisabled.receivedDescription" type="textarea" size="middle"-->
                                      <!--style="width: 95%;"></el-input>-->
                        </el-form-item>
                    </el-form>


                    <h3 v-if="dialogType !== '1'" class="dialog-plate-title"><span>进行中信息</span></h3>
                    <el-form v-if="dialogType !== '1'" :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right"
                             label-width="180px" style="margin-bottom: 0;">
                        <el-form-item label="任务实际开始时间">
                            <el-date-picker v-model="dialogList.startDate" :disabled="!dialogListDisabled.startDate"
                                            format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间"
                                            style="width: 200px;"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="开始创建时间">
                            <el-input v-model="dialogList.startCreateDate"
                                      :disabled="!dialogListDisabled.startCreateDate"></el-input>
                        </el-form-item>
                        <el-form-item label="任务实际结束时间">
                            <el-date-picker v-model="dialogList.endDate" :disabled="!dialogListDisabled.endDate"
                                            format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间"
                                            style="width: 200px;"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="结束创建时间">
                            <el-input v-model="dialogList.endDateCreateDate"
                                      :disabled="!dialogListDisabled.endDateCreateDate"></el-input>
                        </el-form-item>
                        <el-form-item label="任务结果">
                            <el-select v-model="dialogList.taskResult" :disabled="!dialogListDisabled.taskResult">
                                <el-option label="【空】" value="-1"></el-option>
                                <el-option label="完成" value="1"></el-option>
                                <el-option label="未完成" value="0"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="自我评价">
                            <el-select v-model="dialogList.taskSelfEvaluation"
                                       :disabled="!dialogListDisabled.taskSelfEvaluation">
                                <el-option label="【空】" value="-1"></el-option>
                                <el-option label="差" value="1"></el-option>
                                <el-option label="良好" value="2"></el-option>
                                <el-option label="优秀" value="3"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-form>
                    <el-form v-if="dialogType !== '1'" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="自我评价说明">
                            <quill-editor class="task" v-model="dialogList.taskSelfDescription"
                                          @focus="!dialogListDisabled.taskSelfDescription? onEditorFocus($event) : ''"
                                          style="padding-right: 10px;"></quill-editor>
                        </el-form-item>
                    </el-form>

                    <h3 v-if="dialogType !== '1'" class="dialog-plate-title"><span>复核信息</span></h3>
                    <el-form v-if="dialogType !== '1'" :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px" style="margin-bottom: 0;">
                        <el-form-item label="任务是否复核">
                            <el-select v-model="dialogList.isReviewTask" :disabled="!dialogListDisabled.isReviewTask">
                                <el-option label="【空】" value="-1"></el-option>
                                <el-option label="否" value="0"></el-option>
                                <el-option label="是" value="1"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="复核结果">
                            <el-select v-model="dialogList.reviewResult" :disabled="!dialogListDisabled.reviewResult">
                                <el-option label="【空】" value="-1"></el-option>
                                <el-option label="通过" value="1"></el-option>
                                <el-option label="不通过" value="0"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="复核创建时间">
                            <el-input v-model="dialogList.reviewTime"
                                      :disabled="!dialogListDisabled.reviewTime"></el-input>
                        </el-form-item>
                    </el-form>
                    <el-form v-if="dialogType !== '1'" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="任务复核说明">

                            <quill-editor class="task" v-model="dialogList.reviewDescription"
                                          @focus="!dialogListDisabled.reviewDescription? onEditorFocus($event) : ''"
                                          style="padding-right: 10px;"></quill-editor>

                            <!--<el-input v-model="dialogList.reviewDescription"-->
                                      <!--:disabled="!dialogListDisabled.reviewDescription" type="textarea" size="middle"-->
                                      <!--style="width: 95%;"></el-input>-->
                        </el-form-item>
                    </el-form>
                    <div style="text-align: right;margin-right: 1%;">
                        <el-button @click="submitList" :disabled="!dialogBtn" type="primary">确 定</el-button>
                    </div>


                </el-tab-pane>
                <el-tab-pane v-if="dialogType !== '1'" label="过程信息" name="2" :style="dialogHeightPane">
                    <el-button v-if="menuId!=='4594'" @click="insertProcessStateList" type="primary" size="small">新增
                    </el-button>
                    <el-table :data="processStateData.slice((currentPage-1)*pagesize,currentPage*pagesize)" stripe border class="table-index" :height="dialogTableHeight" style="width: 100%;" :header-cell-style="getRowClass">
                        <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                        <el-table-column prop="taskDescription" label="任务说明" sortable min-width="200"></el-table-column>
                        <el-table-column prop="startDate" label="开始时间" sortable min-width="160"></el-table-column>
                        <el-table-column prop="endDate" label="结束时间" sortable min-width="160"></el-table-column>
                        <el-table-column prop="creatTime" label="创建时间" sortable min-width="160"></el-table-column>
                        <el-table-column prop="managerName" label="主管" sortable min-width="100"></el-table-column>
                        <el-table-column prop="managerAdvice" label="主管意见" sortable min-width="150"></el-table-column>
                        <el-table-column prop="adviceCreattime" label="创建时间" sortable min-width="160"></el-table-column>
                        <el-table-column fixed="right" label="操作" sortable align="center" width="90">
                            <template slot-scope="scope">
                                <el-button @click="updateProcessStateList(scope.row)" type="text" size="small">编辑</el-button>
                                <el-button @click="deleteProcessStateList(scope.row)" type="text" size="small">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                   :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]"
                                   :page-size="pagesize" layout="total, sizes, prev, pager, next, jumper"
                                   :total="processStateData.length"></el-pagination>
                </el-tab-pane>
            </el-tabs>
        </el-dialog>

        <!-- 过程状态信息 -->
        <el-dialog :title="dialogProcessStateTitle" width="900px" center :visible.sync="isProcessStateDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <h3 class="dialog-plate-title"><span>基本信息</span></h3>
            <el-form v-model="dialogProcessStateList" label-position="right" label-width="180px"
                     style="margin-bottom: 0;">
                <el-form-item label="*任务说明">
                    <el-input v-model="dialogProcessStateList.taskDescription" type="textarea" mini="middle"
                              style='width: 88%;'></el-input>
                </el-form-item>
            </el-form>
            <el-form :inline="true" class="demo-form-inline" v-model="dialogProcessStateList" label-position="right" label-width="180px">
                <el-form-item label="是否实时时间">
                    <el-select v-model="dialogProcessStateList.isNowTime"  :disabled="dialogProcessStateTitle !=='添加'" >
                        <el-option label="否" value="0"></el-option>
                        <el-option label="是" value="1"></el-option>
                    </el-select>
                </el-form-item>
                <el-checkbox v-model="startChecked" @change="clickStartChecked" class="date-checked" v-if="dialogProcessStateList.isNowTime=='1'"></el-checkbox>
                <el-form-item label="开始时间" class="start-date" v-if="dialogProcessStateList.isNowTime=='1'"><el-input v-model="dialogProcessStateList.startDate" @blur="blurDate('startDate')" ></el-input></el-form-item>
                <el-form-item label="开始时间" class="start-date" v-else><el-date-picker v-model="dialogProcessStateList.startDate" format="yyyy-MM-dd HH:mm:ss"
                                    type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                <br/>
                <el-checkbox v-model="endChecked" @change="clickEndChecked" class="date-checked" v-if="dialogProcessStateList.isNowTime=='1'"></el-checkbox>
                <el-form-item label="结束时间" class="start-date" v-if="dialogProcessStateList.isNowTime=='1'"><el-input v-model="dialogProcessStateList.endDate" @blur="blurDate('endDate')"></el-input></el-form-item>
                <el-form-item label="结束时间" class="start-date" v-else>
                    <el-date-picker v-model="dialogProcessStateList.endDate" @blur="compareDate"
                                    format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间"
                                    style="width: 200px;"></el-date-picker>
                </el-form-item>
                <el-form-item label="创建时间" class="start-date">
                    <el-input v-model="dialogProcessStateList.creatTime" disabled></el-input>
                </el-form-item>
            </el-form>
            <h3 class="dialog-plate-title"><span>主管评审</span></h3>
            <el-form :inline="true" class="demo-form-inline" v-model="dialogProcessStateList" label-position="right"
                     label-width="180px">
                <el-form-item label="主管">
                    <el-input v-model="dialogProcessStateList.managerName"
                              disabled></el-input>
                </el-form-item>
                <el-form-item label="创建时间">
                    <el-input v-model="dialogProcessStateList.adviceCreattime" disabled></el-input>
                </el-form-item>
            </el-form>
            <el-form v-model="dialogProcessStateList" label-position="right" label-width="180px"
                     style="margin-bottom: 0;">
                <el-form-item label="主管意见">
                    <el-input v-model="dialogProcessStateList.managerAdvice"
                              :disabled="dialogProcessStateTitle==='添加'" type="textarea" mini="middle"
                              style='width: 88%;'></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: right;">
                <el-button :disabled="!isProcessStateSubmitBtn" @click="submitProcessStateList" type="primary">确 定
                </el-button>
            </div>
        </el-dialog>


        <!-- 任务说明 -->
        <el-dialog :title="dialogMissionTitle" width="600px" center :visible.sync="isMissionDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <el-form :inline="true" class="demo-form-inline" v-model="dialogMissionList" label-position="right" label-width="180px">
                <el-form-item label="填写内容">
                    <quill-editor v-model="dialogMissionList.content" style="padding-right: 10px;"></quill-editor>
                    <!--<el-input type="textarea" :rows="8" v-model="dialogMissionList.content"-->
                              <!--style="width: 355px;"></el-input>-->
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: right;"><el-button :disabled="!dialogMissionBtn"  @click="submitMissionList" type="primary">确 定</el-button></div>
        </el-dialog>

        <!-- 任务接收说明 -->
        <el-dialog :title="dialogMissionReceiveTitle" width="600px" center :visible.sync="isMissionReceiveDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <el-form :inline="true" class="demo-form-inline" v-model="dialogMissionReceiveList" label-position="right" label-width="180px">
                <el-form-item label="填写内容">
                    <quill-editor v-model="dialogMissionReceiveList.content" style="padding-right: 10px;"></quill-editor>
                    <!--<el-input type="textarea" :rows="8" v-model="dialogMissionReceiveList.content"
                              style="width: 355px;"></el-input>-->
                          </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: right;"><el-button :disabled="!dialogMissionReceiveBtn" @click="submitMissionReceiveList" type="primary">确 定</el-button></div>
        </el-dialog>

        <!-- 使用说明 -->
        <el-dialog title="使用说明" width="800px" top="50px" :visible.sync="isInstructionsDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">
           <div :style="instructionsHeight">
               <quill-editor v-model="instructions.content" @focus="!jurisdiction.updateSoftDescription? onEditorFocus($event) : ''" :style="instructionsQuillHeight"></quill-editor>
           </div>
            <div slot="footer" class="dialog-footer" style="text-align: right;">
                <el-button :disabled="!dialogInstructionsBtn" @click="submitInstructions" type="primary">确 定</el-button>
            </div>
        </el-dialog>

    </div>
</template>

<script>

    import 'quill/dist/quill.core.css';
    import 'quill/dist/quill.snow.css';
    import 'quill/dist/quill.bubble.css';
    import {quillEditor} from 'vue-quill-editor';

    export default {
        name: "",
        components: {quillEditor},
        data() {
            let token = sessionStorage.getItem("tokenId");
            let menuId = sessionStorage.getItem('menuId');
            let tableHeight = menuId === '4594' ? (document.documentElement.clientHeight - 170) : (document.documentElement.clientHeight - 140);
            return {
                tokenId: token,
                menuId: menuId,
                currentPage: 1,
                pagesize: 10,
                activeName: '1',
                performName: [],
                deptors: [],
                tableHeight: tableHeight,
                dataList: [],

                //基本信息
                isDialog: false,
                dialogTitle: '',
                dialogBtn: true,
                dialogType: '',
                dialogHeightPane: {
                    height: (document.documentElement.clientHeight - 180) + 'px',
                    overflowY: 'auto'
                },
                dialogTableHeight: document.documentElement.clientHeight - 260,
                dialogList: {
                    isEveryDayTask: '',
                    isReviewTask: '',
                    reviewResult: '',
                    reviewTime: '',
                    reviewDescription: '',
                    createDate: '',
                    creator: '',
                    creatorName: '',
                    dept: '',
                    deptName: '',
                    endDate: '',
                    endDateCreateDate: '',
                    finishDate: '',
                    id: '',
                    isReceived: '',
                    performer: '',
                    performerName: '',
                    receivedDate: '',
                    receivedDescription: '',
                    startCreateDate: '',
                    startDate: '',
                    taskContent: '',
                    taskName: '',
                    taskResult: '',
                    taskSelfDescription: '',
                    taskSelfEvaluation: '',
                    taskState: '',
                },
                dialogListDisabled: {
                    isEveryDayTask:true,
                    isReviewTask: true,
                    reviewResult: true,
                    reviewTime: true,
                    reviewDescription: true,
                    createDate: true,
                    creator: true,
                    creatorName: true,
                    dept: true,
                    deptName: true,
                    endDate: true,
                    endDateCreateDate: true,
                    finishDate: true,
                    id: true,
                    isReceived: true,
                    performer: true,
                    performerName: true,
                    receivedDate: true,
                    receivedDescription: true,
                    startCreateDate: true,
                    startDate: true,
                    taskContent: true,
                    taskName: true,
                    taskResult: true,
                    taskSelfDescription: true,
                    taskSelfEvaluation: true,
                    taskState: true,
                },
                isEveryDayTask: true,

                // 是否打开接收信息
                // isReceiveBtn: true,
                // isOnGoingBtn: true,
                // isReviewBtn: true,


                //过程状态信息
                isProcessStateDialog: false,
                dialogProcessStateTitle: '',
                dialogProcessStateList: {
                    adviceCreattime: "",
                    creatTime: "",
                    creator: "",
                    endDate: "",
                    id: "",
                    manager: "",
                    managerAdvice: "",
                    isNowTime: "",
                    managerName: "",
                    startDate: "",
                    taskDescription: "",
                    taskId: "",
                },
                processStateData: [],
                isProcessStateSubmitBtn: true,
                startChecked: false,
                endChecked: false,


                //任务说明
                isMissionDialog: false,
                dialogMissionTitle: '',
                dialogMissionBtn: true,
                dialogMissionList: {
                    content: '',
                    id: '',
                    object: '',
                    person: '',
                    personName: '',
                    tid: '',
                    time: '',
                    type: '',
                },
                missionData: [],


                //任务接收说明
                isMissionReceiveDialog: false,
                dialogMissionReceiveTitle: '',
                dialogMissionReceiveBtn: true,
                dialogMissionReceiveList: {
                    content: '',
                    id: '',
                    object: '',
                    person: '',
                    personName: '',
                    tid: '',
                    time: '',
                    type: '',
                },
                missionReceiveData: [],

                //使用说明
                jurisdiction:{
                    updateSoftDescription:true
                },
                isInstructionsDialog:false,
                dialogInstructionsBtn: true,
                instructionsHeight: {
                    height: (document.documentElement.clientHeight - 230) + 'px',
                    overflowY: 'auto'
                },
                instructionsQuillHeight: {
                    height: (document.documentElement.clientHeight - 300) + 'px'
                },
                isInstructionsBtn:true,
                instructions:{
                    content: '',
                    id: '',
                    type: '',
                },

            };
        },
        created() {
            this.getData();
            this.getDepts();
            this.getInstructions();
            this.getJurisdiction();
        },
        methods: {
            getDepts() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/taskManager/selectDepts?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.deptors = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            getPerform(id) {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/taskManager/selectTaskPerformPerson/' + id + '?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.performName = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            getData() {
                let _this = this;
                let loading = this.$loading({
                    target: document.querySelector(".wrapper > .content-box"),
                    lock: true,
                    text: '正在努力加载中...',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.8)'
                });
                let id;
                if (_this.menuId === '4592') {
                    id = '/api/adscm/operation/taskManager/selectMyTaskManager/0?tokenId=' + _this.tokenId;
                } else if (_this.menuId === '4593') {
                    id = '/api/adscm/operation/taskManager/selectMyTaskManager/1?tokenId=' + _this.tokenId;
                } else if (_this.menuId === '4594') {
                    id = '/api/adscm/operation/taskManager/selectTaskManager?tokenId=' + _this.tokenId;
                }
                this.$http({
                    url: id,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.dataList = res.data.content;
                        loading.close();
                    } else {
                        _this.$message.error(res.data.desc);
                        loading.close();
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                    loading.close();
                })
            },
            changeDept() {
                this.getPerform(this.dialogList.dept)
            },
            insertList() {
                this.isDialog = true;
                this.dialogType = '1';
                this.isEveryDayTask = false;
                this.dialogListDisabled = {
                    isReviewTask: false,
                    reviewResult: false,
                    reviewTime: false,
                    reviewDescription: false,
                    createDate: false,
                    creator: false,
                    creatorName: false,
                    dept: true,
                    deptName: false,
                    endDate: false,
                    endDateCreateDate: false,
                    finishDate: true,
                    id: false,
                    isReceived: false,
                    performer: true,
                    performerName: true,
                    receivedDate: false,
                    receivedDescription: false,
                    startCreateDate: false,
                    startDate: false,
                    taskContent: true,
                    taskName: true,
                    taskResult: false,
                    taskSelfDescription: false,
                    taskSelfEvaluation: false,
                    taskState: false,
                    isEveryDayTask: false,
                };
                this.dialogList = {
                    isEveryDayTask: '',
                    isReviewTask: '',
                    reviewResult: '',
                    reviewTime: '',
                    reviewDescription: '',
                    createDate: '',
                    creator: '',
                    creatorName: '',
                    dept: 1,
                    deptName: '',
                    endDate: '',
                    endDateCreateDate: '',
                    finishDate: '',
                    id: '',
                    isReceived: '',
                    performer: '',
                    performerName: '',
                    receivedDate: '',
                    receivedDescription: '',
                    startCreateDate: '',
                    startDate: '',
                    taskContent: '',
                    taskName: '',
                    taskResult: '',
                    taskSelfDescription: '',
                    taskSelfEvaluation: '',
                    taskState: '',
                };
                this.getPerform(this.deptors[0].id)
            },
            insertThisDayList() {
                let _this = this;
                this.$confirm('是否生成每日任务?', '提示', {
                    confirmButtonClass: 'el-button--warning'
                }).then(() => {
                    this.$http({
                        url: '/api/adscm/operation/taskManager/insertEverDayTask?tokenId=' + _this.tokenId,
                        method: 'post',
                        headers: {'X-Requested-With': 'XMLHttpRequest'},
                    }).then(function (res) {
                        if (res.data.statusCode == 200) {
                            _this.$message.success('已经创办每日任务！');
                        } else {
                            _this.$message.error(res.data.desc);
                        }
                    }).catch(function (catchres) {
                        _this.$message.error("加载失败！请重新加载...");
                    })
                }).catch(() => {
                });
            },
            updateList(row) {
                this.isDialog = true;
                this.dialogType = '2';
                this.activeName = row.isEveryDayTask == 1 ? '2' : '1';
                this.isEveryDayTask = row.isEveryDayTask == 1 ? true : false;

                this.dialogListDisabled = {
                    isReviewTask: (this.menuId === '4594' && row.isReceived == 1) ? true : false,
                    reviewResult: (this.menuId === '4594' && row.isReceived == 1) ? true : false,
                    reviewDescription: (this.menuId === '4594' && row.isReceived == 1) ? true : false,
                    reviewTime: false,
                    createDate: false,
                    creator: false,
                    creatorName: false,
                    dept: this.menuId === '4594' ? (row.isReceived != 1 ? true : false) : false,
                    deptName: this.menuId === '4594' ? (row.isReceived != 1 ? true : false) : false,
                    endDate: this.menuId === '4592' ? true : false,
                    endDateCreateDate: false,
                    finishDate: this.menuId === '4594' ? (row.isReceived != 1 ? true : false) : false,
                    id: false,
                    isReceived: this.menuId === '4592' ? true : false,
                    performer: this.menuId === '4594' ? (row.isReceived != 1 ? true : false) : false,
                    performerName: this.menuId === '4594' ? (row.isReceived != 1 ? true : false) : false,
                    receivedDate: false,
                    receivedDescription: this.menuId === '4592' ? true : false,
                    startCreateDate: false,
                    startDate: this.menuId === '4592' ? true : false,
                    taskContent: this.menuId === '4594' ? (row.isReceived != 1 ? true : false) : false,
                    taskName: this.menuId === '4594' ? (row.isReceived != 1 ? true : false) : false,
                    taskResult: this.menuId === '4592' ? true : false,
                    taskSelfDescription: this.menuId === '4592' ? true : false,
                    taskSelfEvaluation: this.menuId === '4592' ? true : false,
                    taskState: false,
                };
                this.dialogList = row;

                if (row.isEveryDayTask == 1) {
                    this.getProcessStateData();
                }

                this.getMissionData();
                this.getMissionReceiveData();

                this.dialogList.dept = parseInt(this.dialogList.dept);
                this.dialogList.performer = parseInt(this.dialogList.performer);
                this.dialogList.isReceived = this.dialogList.isReceived ? this.dialogList.isReceived.toString() : '';
                this.getPerform(this.dialogList.dept);
            },
            submitList() {
                let _this = this;
                let url;
                if (_this.dialogType === '1') {
                    url = '/api/adscm/operation/taskManager/insert?tokenId=' + _this.tokenId;
                } else if (_this.dialogType === '2') {
                    url = '/api/adscm/operation/taskManager/update?tokenId=' + _this.tokenId;
                }
                _this.dialogList.finishDate = _this.timestampToTime(_this.dialogList.finishDate);
                _this.dialogList.startDate = _this.timestampToTime(_this.dialogList.startDate);
                _this.dialogList.endDate = _this.timestampToTime(_this.dialogList.endDate);
                if ( _this.dialogList.taskName === '') {
                    _this.$message.error("任务名称不能为空！");
                } else if ( _this.dialogList.finishDate === '') {
                    _this.$message.error("完成时间不能为空！");
                } else if ( _this.dialogList.dept === '') {
                    _this.$message.error("任务执行人所属部门不能为空！");
                } else if ( _this.dialogList.performer === '') {
                    _this.$message.error("任务执行人不能为空！");
                } else{
                    _this.dialogBtn = false;
                    this.$http({
                        url: url,
                        method: 'post',
                        headers: {'X-Requested-With': 'XMLHttpRequest'},
                        data: _this.dialogList,
                    }).then(function (res) {
                        if (res.data.statusCode == 200) {
                            _this.isDialog = false;
                            _this.getData();

                        } else {
                            _this.$message.error(res.data.desc);
                        }
                        _this.dialogBtn = true;
                    }).catch(function (catchres) {
                        _this.$message.error("加载失败！请重新加载...");
                        _this.dialogBtn = true;
                    })
                }
            },

            //过程状态信息
            getProcessStateData() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/taskManagerdetail/selectByTid/' + _this.dialogList.id + '?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.processStateData = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            insertProcessStateList() {
                this.isProcessStateDialog = true;
                this.dialogProcessStateTitle = '添加';
                this.dialogProcessStateList = {
                    adviceCreattime: "",
                    creatTime: "",
                    creator: "",
                    endDate: "",
                    isNowTime: "",
                    id: "",
                    manager: "",
                    managerAdvice: "",
                    managerName: "",
                    startDate: "",
                    taskDescription: "",
                    taskId: this.dialogList.id,
                };
            },
            updateProcessStateList(row) {
                this.isProcessStateDialog = true;
                this.dialogProcessStateTitle = '编辑';
                this.dialogProcessStateList = row;
            },
            deleteProcessStateList(row) {
                let _this = this;
                this.$confirm('是否生成每日任务?', '提示', {
                    confirmButtonClass: 'el-button--warning'
                }).then(() => {
                    _this.$http({
                        url: '/api/adscm/operation/taskManagerdetail/delete/'+row.id+'?tokenId='+_this.tokenId,
                        method: 'post',
                        headers: {'X-Requested-With': 'XMLHttpRequest'},
                    }).then(function (res) {
                        if (res.data.statusCode == 200) {
                            _this.getProcessStateData();
                        } else {
                            _this.$message.error(res.data.desc);
                        }
                    }).catch(function (catchres) {_this.$message.error("加载失败！请重新加载...");})

                }).catch(() => {});
            },

            clickStartChecked() {
                if (this.startChecked) {
                    this.blurDate('startDate');
                }
            },
            clickEndChecked() {
                if (this.endChecked) {
                    this.blurDate('endDate');
                }
            },
            blurDate(time) {
                let date = new Date();
                let Y = date.getFullYear() + '-';
                let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + " ";
                let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ":";
                let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ":";
                let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                let thisTime = Y + M + D + h + m + s;
                this.dialogProcessStateList[time] = thisTime;
                if (time === 'endDate') {
                    this.compareDate();
                }

            },
            compareDate() {
                let start = this.timestampToTime(this.dialogProcessStateList.startDate).substr(0, 10);
                let end = this.timestampToTime(this.dialogProcessStateList.endDate).substr(0, 10);
                let date1 = new Date(this.dialogProcessStateList.startDate).getTime();
                let date2 = new Date(this.dialogProcessStateList.endDate).getTime();
                if (start !== end) {
                    this.isProcessStateSubmitBtn = false;
                    this.$message.error('开始时间和结束时间需要同一天!');
                } else if (date1 > date2) {
                    this.isProcessStateSubmitBtn = false;
                    this.$message.error('开始时间必须早于结束时间!');
                } else {
                    this.isProcessStateSubmitBtn = true;
                }
            },
            submitProcessStateList() {
                let _this = this;
                let url;
                if (_this.dialogProcessStateTitle === '添加') {
                    url = '/api/adscm/operation/taskManagerdetail/insert?tokenId=' + _this.tokenId;
                } else if (_this.dialogProcessStateTitle === '编辑') {
                    url = '/api/adscm/operation/taskManagerdetail/update?tokenId=' + _this.tokenId;
                }

                this.dialogProcessStateList.startDate =  this.dialogProcessStateList.isNowTime=='1' ? this.dialogProcessStateList.startDate : this.timestampToTime(this.dialogProcessStateList.startDate);
                this.dialogProcessStateList.endDate =  this.dialogProcessStateList.isNowTime=='1' ? this.dialogProcessStateList.endDate : this.timestampToTime(this.dialogProcessStateList.endDate);

                if ( _this.dialogProcessStateList.taskDescription === '') {
                    _this.$message.error("任务说明不能为空！");
                } else{
                    this.$http({
                        url: url,
                        method: 'post',
                        headers: {'X-Requested-With': 'XMLHttpRequest'},
                        data: _this.dialogProcessStateList,
                    }).then(function (res) {
                        if (res.data.statusCode == 200) {
                            _this.isProcessStateDialog = false;
                            _this.getProcessStateData();
                        } else {
                            _this.$message.error(res.data.desc);
                        }
                    }).catch(function (catchres) {
                        _this.$message.error("加载失败！请重新加载...");
                    })
                }

            },


            //任务说明
            getMissionData() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/taskManagerinfo/selectByTid/1/' + _this.dialogList.id  + '?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.missionData = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            insertMissionList() {
                this.isMissionDialog = true;
                this.dialogMissionTitle = '添加';
                this.dialogMissionList = {
                    content: '',
                    id: '',
                    object: '',
                    person: '',
                    personName: '',
                    time: '',
                    type: '',
                    tid: this.dialogList.id,
                };
            },
            updateMissionList(row) {
                this.isMissionDialog = true;
                this.dialogMissionTitle = '编辑';
                this.dialogMissionList = row;
            },
            submitMissionList() {
                let _this = this;
                let url;
                if (_this.dialogMissionTitle === '添加') {
                    url = '/api/adscm/operation/taskManagerinfo/insert/1?tokenId=' + _this.tokenId;
                } else if (_this.dialogMissionTitle === '编辑') {
                    url = '/api/adscm/operation/taskManagerinfo/update?tokenId=' + _this.tokenId;
                }

                _this.dialogMissionBtn = false;

                this.$http({
                    url: url,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                    data: _this.dialogMissionList,
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.isMissionDialog = false;
                        _this.getMissionData();
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                    _this.dialogMissionBtn = true;
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                    _this.dialogMissionBtn = true;
                })
            },

            //任务接收说明
            getMissionReceiveData() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/taskManagerinfo/selectByTid/2/' + _this.dialogList.id  + '?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.missionReceiveData = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            insertMissionReceiveList() {
                this.isMissionReceiveDialog = true;
                this.dialogMissionReceiveTitle = '添加';
                this.dialogMissionReceiveList = {
                    content: '',
                    id: '',
                    object: '',
                    person: '',
                    personName: '',
                    time: '',
                    type: '',
                    tid: this.dialogList.id,
                };
            },
            updateMissionReceiveList(row) {
                this.isMissionReceiveDialog = true;
                this.dialogMissionReceiveTitle = '编辑';
                this.dialogMissionReceiveList = row;
            },
            submitMissionReceiveList() {
                let _this = this;
                let url;
                if (_this.dialogMissionReceiveTitle === '添加') {
                    url = '/api/adscm/operation/taskManagerinfo/insert/2?tokenId=' + _this.tokenId;
                } else if (_this.dialogMissionReceiveTitle === '编辑') {
                    url = '/api/adscm/operation/taskManagerinfo/update?tokenId=' + _this.tokenId;
                }
                _this.dialogMissionReceiveBtn = false;
                this.$http({
                    url: url,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                    data: _this.dialogMissionReceiveList,
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.isMissionReceiveDialog = false;
                        _this.getMissionReceiveData();
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                    _this.dialogMissionReceiveBtn = true;
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                    _this.dialogMissionReceiveBtn = true;
                })
            },


            // 使用说明
            getJurisdiction() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/system/menu/getMenuAllSrc/' + _this.menuId + '?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        for (let i = 0; i < res.data.content.length; i++) {
                            let item = res.data.content[i];
                            _this.jurisdiction[item.component] = item.menuShow;
                        }
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            getInstructions(){
                let _this= this;
                this.$http({
                    url: '/api/adscm/operation/jySoftDescription/selectByTid/dzjz?tokenId='+this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.instructions = res.data.content[0];
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            openInstructions(){
                this.isInstructionsDialog = true;
            },
            submitInstructions(){
                let _this= this;
                _this.dialogInstructionsBtn= false;
                this.$http({
                    url: '/api/adscm/operation/jySoftDescription/update?tokenId='+_this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                    data: _this.instructions,
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.isInstructionsDialog = false;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                    _this.dialogInstructionsBtn= true;
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                    _this.dialogInstructionsBtn= true;
                })
            },

            handleClick(tab, event) {
                if (tab.name === '2') {
                    this.getProcessStateData();
                }
            },
            handleSizeChange: function (size) {
                this.pagesize = size;
            },
            handleCurrentChange: function (currentPage) {
                this.currentPage = currentPage;
            },
            timestampToTime(timestamp) {
                if (timestamp) {
                    let date = new Date(timestamp);
                    let Y = date.getFullYear() + '-';
                    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                    let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + " ";
                    let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ":";
                    let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ":";
                    let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                    return timestamp ? Y + M + D + h + m + s : '';
                } else {
                    return '';
                }
            },
        }
    }
</script>

<style scoped>

    #parts .el-table--small {
        font-size: 13px;
    }

    #parts .el-table .cell,
    #parts .el-table th div {
        padding-left: 0;
        padding-right: 0;
    }

    #parts .el-tab-pane.dialog1 .el-form {
        margin-bottom: 30px;
    }

    .date-checked {
        transform: translate(86px, 8px);
        z-index: 666;
    }

    .start-date {
        transform: translateX(-20px);
    }

    .task .ql-container {
        min-height: 200px;
    }
</style>
